# -*- python -*-
# ex: set syntax=python:

# This is a sample buildmaster config file. It must be installed as
# 'master.cfg' in your buildmaster's base directory (although the filename
# can be changed with the --basedir option to 'mktap buildbot master').

# It has one job: define a dictionary named BuildmasterConfig. This
# dictionary has a variety of keys to control different aspects of the
# buildmaster. They are documented in docs/config.xhtml .


# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

####### BUILDSLAVES

from buildbot.buildslave import BuildSlave
from tgbuilder import createslavelist
slavelist, namelist = createslavelist()
c['slaves'] = slavelist


# 'slavePortnum' defines the TCP port to listen on. This must match the value
# configured into the buildslaves (with their --master option)

c['slavePortnum'] = 9989

####### CHANGESOURCES
    def split_file_branches(path):
         pieces = path.split('/')
         if pieces[0] == 'trunk':
             return (None, '/'.join(pieces[1:]))
         elif pieces[0] == 'branches':
             return ('/'.join(pieces[0:2]),
                     '/'.join(pieces[2:]))
         else:
             return None
            
from buildbot.changes.svnpoller import SVNPoller
c['change_source'] = SVNPoller("http://svn.turbogears.org/",split_file=split_file_branches)


####### SCHEDULERS

## configure the Schedulers

from buildbot.scheduler import Scheduler
from buildbot.scheduler import Periodic

c['schedulers'] = []
c['schedulers'].append(Periodic('TG',["TG1-full","TG11-full","TG2-full"],60*90))

c['schedulers'].append[Scheduler(name="TG1-f",branch="1.0",treeStableTimer=90*60,
                         builderNames=["TG1-full"])
c['schedulers'].append[Scheduler(name="TG11-f",branch="1.1",treeStableTimer=90*60,
                         builderNames=["TG11-full"])
c['schedulers'].append[Scheduler(name="TG2-f",branch=None,treeStableTimer=90*60,
                         builderNames=["TG2-full"])
                         
c['schedulers'].append[Scheduler(name="TG1-q",branch="1.0",treeStableTimer=5*60,
                         builderNames=["TG1-quick"])
c['schedulers'].append[Scheduler(name="TG11-q",branch="1.1",treeStableTimer=5*60,
                         builderNames=["TG11-quick"])
c['schedulers'].append[Scheduler(name="TG2-q",branch=None,treeStableTimer=5*60,
                         builderNames=["TG2-quick"])
                         
c['schedulers'].append(Periodic("doc",
                ["docBuilder","TG_NG_SETUP"],60*5))

c['schedulers'].append(Periodic("dependencies",
                ["Cheetah","RuleDispatch","PyProtocol","SimpleJSON","cElementTree"],60*60*24))

####### BUILDERS

# the 'builders' list defines the Builders. Each one is configured with a
# dictionary, using the following keys:
#  name (required): the name used to describe this bilder
#  slavename (required): which slave to use, must appear in c['bots']
#  builddir (required): which subdirectory to run the builder in
#  factory (required): a BuildFactory to define how the build is run
#  periodicBuildTime (optional): if set, force a build every N seconds

# buildbot/process/factory.py provides several BuildFactory classes you can
# start with, which implement build processes for common targets (GNU
# autoconf projects, CPAN perl modules, etc). The factory.BuildFactory is the
# base class, and is configured with a series of BuildSteps. When the build
# is run, the appropriate buildslave is told to execute each Step in turn.

# the first BuildStep is typically responsible for obtaining a copy of the
# sources. There are source-obtaining Steps in buildbot/process/step.py for
# CVS, SVN, and others.

from tgbuilder import *

######## Documentation ###################
fdoc_tg1 = doc_builder("bin:lib",framework='script',svnurl='http://svn.turbogears.org/branches/1.0',doc_dir="doc")

######## BuildFactories for TurboGears ###
ftg1   = tg10builder("bin:lib")
ftg11 = tg11builder("bin:lib")
ftg2   = tg2builder("bin:lib")

ftg1q   = tg10builder("bin:lib",True)
ftg11q = tg11builder("bin:lib",True)
ftg2q   = tg2builder("bin:lib",True)

ftg_ng = tg_ng_setupbuilder("bin:lib")

############# RuleDispatch ###############
fruledispatch = dependencybuildersvn("svn://svn.eby-sarna.com/svnroot/RuleDispatch","bin:lib","RuleDispatch",["PyProtocols"])

############# simplejson #################
fsimplejson = dependencybuildersvn("http://simplejson.googlecode.com/svn/trunk/","bin:lib","SimpleJSON")

############# PyProtocols #################
fpyprotocol = dependencybuildersvn("svn://svn.eby-sarna.com/svnroot/PyProtocols","bin:lib","PyProtocols",["RuleDispatch"])

############# Cheetah - Build from Source
fcheetah = dependencybuilderee(["cheetah"],"bin:lib")

############# cElementTree
fcelementtree = dependencybuilderee(["celementtree"],"bin:lib")

############# Namelists of slaves #############
py23list = createnamelist(namelist,"23")
py24list = createnamelist(namelist,"24")
py25list = createnamelist(namelist,"25")
doclist = createnamelist(namelist,"doc")

############# Defining Builder ##############
b1 = {'name': "TG1-full",
      'slavenames': namelist,
      'builddir': "TG1full",
      'factory': ftg1
      }
c['builders'] = [b1]

b2 = {'name': "TG11-full",
      'slavenames': py24list+py25list,
      'builddir': "TG11full",
      'factory': ftg11
      }
c['builders'] .append(b2)

b3 = {'name': "TG2-full",
      'slavenames': py24list+py25list,
      'builddir': "TG2full",
      'factory': ftg2
      }
c['builders'] .append(b3)

b4 = {'name': "Cheetah",
      'slavenames': py24list+py25list,
      'builddir': "cheetah",
      'factory': fcheetah
      }
c['builders'].append(b4)

b5 = {'name': "RuleDispatch",
      'slavenames': py24list+py25list,
      'builddir': "ruledispatch",
      'factory': fruledispatch
      }
c['builders'].append(b5)

b6 = {'name': "SimpleJSON",
      'slavenames': py24list+py25list,
      'builddir': "simplejson",
      'factory': fsimplejson
      }
c['builders'].append(b6)

b7 = {'name': "PyProtocol",
      'slavenames': py24list+py25list,
      'builddir': "pyprotocol",
      'factory': fpyprotocol
      }
c['builders'].append(b7)

b8 = {'name': "cElementTree",
      'slavenames': py24list+py25list,
      'builddir': "celementtree",
      'factory': fcelementtree
      }
c['builders'].append(b8)

b9 = {'name': "TG_NG_SETUP",
      'slavenames': py24list+py25list,
      'builddir': "tgng",
      'factory': ftg_ng
      }
c['builders'].append(b9)

b10 = {'name': "docBuilder",
      'slavenames': doclist,
      'builddir': "doc_builder",
      'factory': fdoc_tg1
      }
c['builders'].append(b10)

b11 = {'name': "TG1-quick",
      'slavenames': namelist,
      'builddir': "TG1quick",
      'factory': ftg1q
      }
c['builders'] .append(b11)

b12 = {'name': "TG11-quick",
      'slavenames': py24list+py25list,
      'builddir': "TG11quick",
      'factory': ftg11q
      }
c['builders'] .append(b12)

b13 = {'name': "TG2-quick",
      'slavenames': py24list+py25list,
      'builddir': "TG2quick",
      'factory': ftg2q
      }
c['builders'] .append(b13)

####### STATUS TARGETS

# 'status' is a list of Status Targets. The results of each build will be
# pushed to these targets. buildbot/status/*.py has a variety to choose from,
# including web pages, email senders, and IRC bots.

c['status'] = []

from buildbot.status import html
c['status'].append(html.WebStatus(http_port=8010,allowForce=True))

from buildbot.status import mail
c['status'].append(mail.MailNotifier(fromaddr="buildbot-no-reply@turbogears.org",
                                      extraRecipients=["turbogears-builds@googlegroups.com"],
                                      sendToInterestedUsers=False,
                                      subject="%(builder)s failed",
                                      mode="problem",
                                      addLogs=True))
#
# from buildbot.status import words
# c['status'].append(words.IRC(host="irc.example.com", nick="bb",
#                              channels=["#example"]))
#
from buildbot.status import client
c['status'].append(client.PBListener(9988))


####### DEBUGGING OPTIONS

# if you set 'debugPassword', then you can connect to the buildmaster with
# the diagnostic tool in contrib/debugclient.py . From this tool, you can
# manually force builds and inject changes, which may be useful for testing
# your buildmaster without actually commiting changes to your repository (or
# before you have a functioning 'sources' set up). The debug tool uses the
# same port number as the slaves do: 'slavePortnum'.

#c['debugPassword'] = "debugpassword"

# if you set 'manhole', you can ssh into the buildmaster and get an
# interactive python shell, which may be useful for debugging buildbot
# internals. It is probably only useful for buildbot developers. You can also
# use an authorized_keys file, or plain telnet.
#from buildbot import manhole
#c['manhole'] = manhole.PasswordManhole("tcp:9999:interface=127.0.0.1",
#                                       "admin", "password")


####### PROJECT IDENTITY

# the 'projectName' string will be used to describe the project that this
# buildbot is working on. For example, it is used as the title of the
# waterfall HTML page. The 'projectURL' string will be used to provide a link
# from buildbot HTML pages to your project's home page.

c['projectName'] = "TurboGears"
c['projectURL'] = "http://turbogears.org/"

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server (usually the html.Waterfall page) is visible. This
# typically uses the port number set in the Waterfall 'status' entry, but
# with an externally-visible host name which the buildbot cannot figure out
# without some help.

c['buildbotURL'] = "http://localhost:8010/"
